package GameEngine.Collision;

public class Area extends CollisionObject  {
	protected int width;
	protected int height;

	public Area(int px, int py, int w, int h) {
		posx = px;
		posy = py;
		width = w;
		height = h;
	}

	@Override
	public boolean inside(Point p) {
		if ((p.x >= posx) && (p.x <= (posx + width))) {
			if ((p.y >= posy) && (p.y <= (posy + height))) {
				return true;
			}
		}
		return false;
	}

	@Override
	public boolean overlap(CollisionObject co) {
		if (co instanceof Area) {
			Area a = (Area) co;
			return this.inside(new Point(a.posx, co.posy))
					|| this.inside(new Point(a.posx + a.width, a.posy))
					|| this.inside(new Point(a.posx, a.posy + a.height))
					|| this.inside(new Point(a.posx + a.width, a.posy + a.height))

					|| a.inside(new Point(this.posx, this.posy))
					|| a.inside(new Point(this.posx + this.width, this.posy))
					|| a.inside(new Point(this.posx, this.posy + this.height))
					|| a.inside(new Point(this.posx + this.width, this.posy
							+ this.height));
		}
		return false;
	}
}